
# =============================
# helper functions
# =============================

add_library( testHelperFunctions 
	mesh_testFunctions.hpp
	mesh_testFunctions.cpp
	testFunctions.hpp
	testFunctions.cpp
	structMesh_testFunctions.hpp
	structMesh_testFunctions.cpp
)

target_include_directories( testHelperFunctions PUBLIC
	${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries( testHelperFunctions PUBLIC
	mesh
)

# =============================
# test suites
# =============================

# mesh
add_subdirectory(mesh)


# solverBase
add_subdirectory(solverBase)


# sweSolver
add_subdirectory(sweSolver)

# other
add_executable( unitTests
	catch2_main.cpp
	#
	util_test.cpp
	unifiedMathFunctions_test.cpp
	streamAccess_test.cpp
	cubicRoot_test.cpp
	#
	gmshImport_test.cpp
	gmshImport_testMSH.hpp
	#
	vtkMeshExport_test.cpp
	vtkMeshImport_test.cpp
	vtkFieldExport_test.cpp
	vtkFieldImport_test.cpp
	vtkFieldImport_boundary_test.cpp
	vtkFieldImport_constant_test.cpp
	vtkFieldImport_source_test.cpp
	#
	rasterTest.cpp
	INIReader_extension_test.cpp
)

target_link_libraries( unitTests
	Catch2
	util
	gmshImport
	vtkInterface
	rasterReader
	settingsImport
	testHelperFunctions
)
target_compile_options( unitTests PRIVATE -w )


# execute all tests
# add_custom_command(
# 	TARGET unitTests POST_BUILD
add_custom_target( allTests ALL
	COMMAND echo meshTests
	COMMAND meshTests
	COMMAND echo solverBaseTests
	COMMAND solverBaseTests "~[slow]"
	COMMAND echo sweSolverTests
	COMMAND sweSolverTests "~[pureOutput]" --testDir ${CMAKE_CURRENT_SOURCE_DIR}/sweSolver
	COMMAND echo unitTests
	COMMAND unitTests --testDir ${CMAKE_CURRENT_SOURCE_DIR}
	DEPENDS
		meshTests
		solverBaseTests
		sweSolverTests
		unitTests
	COMMENT "Running tests..."
)


if (WIN32 OR MSYS OR MINGW)
	# dlls must be in the same dir as the executables that use them.
	add_custom_command(TARGET unitTests POST_BUILD
		# COMMAND ${CMAKE_COMMAND} -E copy_if_different
		# $<TARGET_FILE:catch2>        # in-file
		# $<TARGET_FILE_DIR:unitTests> # out-file path
		COMMAND ${CMAKE_COMMAND} -E copy_if_different
		$<TARGET_FILE:fparser>
		$<TARGET_FILE_DIR:unitTests>
		COMMAND ${CMAKE_COMMAND} -E copy_if_different
		$<TARGET_FILE:tinyxml2>
		$<TARGET_FILE_DIR:unitTests>
	)
endif()


# # coverage testing (produces annoying errors about existing data with
# # different time stamp, let's revisit this later)
# if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
# 	target_compile_options( unitTests PUBLIC
# 		-fprofile-arcs
# 		-ftest-coverage
# 		--coverage
# 	)
# 	target_link_options( unitTests PUBLIC
# 		-fprofile-arcs
# 		-ftest-coverage
# 		--coverage
# 		-lgcov
# 	)
# endif()

add_subdirectory(distr)
